package com.kantboot.business.gc.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.kantboot.business.gc.domain.dto.BusGcTypeI18nDTO;
import com.kantboot.business.gc.domain.dto.BusGcTypeI18nSaveDTO;
import com.kantboot.business.gc.domain.entity.BusGcTypeI18n;
import com.kantboot.business.gc.repository.BusGcTypeI18nRepository;
import com.kantboot.business.gc.service.IBusGcTypeI18nService;
import com.kantboot.util.core.param.PageParam;
import com.kantboot.util.core.result.PageResult;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class BusGcTypeI18nServiceImpl implements IBusGcTypeI18nService {

    @Resource
    private BusGcTypeI18nRepository i18nRepository;

    @Override
    public void addLanguage(BusGcTypeI18nSaveDTO saveDTO) {
        BusGcTypeI18n busGcTypeI18n = new BusGcTypeI18n();
        BeanUtil.copyProperties(saveDTO,busGcTypeI18n);
        i18nRepository.save(busGcTypeI18n);
    }

    @Override
    public PageResult getLanguageListByTypeId(PageParam<BusGcTypeI18nDTO> pageParam) {
        if (pageParam.getData() == null || pageParam.getData().getTypeId() == null) {
            throw new RuntimeException("参数不能为空");
        }
       return PageResult.of(i18nRepository.getLanguageListByTypeId(pageParam.getData(), pageParam.getPageable()));
    }

    @Override
    public void deleteLanguage(List<BusGcTypeI18nSaveDTO> busGcTypeI18nSaveDTOList) {
        List<BusGcTypeI18n> busGcTypeI18nList = BeanUtil.copyToList(busGcTypeI18nSaveDTOList, BusGcTypeI18n.class);
        i18nRepository.deleteAllInBatch(busGcTypeI18nList);
    }
}
